package it.asvp.asvp_portal.data.entity.library;


import static javax.persistence.GenerationType.IDENTITY;
import it.asvp.asvp_portal.data.entity.domain.BaseEntity;
import it.asvp.asvp_portal.data.entity.library.LibraryComment;
import it.asvp.asvp_portal.data.entity.library.LibraryPicture;
import it.asvp.asvp_portal.data.entity.member.Member;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@SuppressWarnings("serial")
@Entity
@Table(name = "library", catalog = "asvp_db", uniqueConstraints = @UniqueConstraint(columnNames = {
		"title", "author" }))
public class Library extends BaseEntity {

	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	private Long id;
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "id_member", nullable = false)
	private Member member;
	
	@Column(name = "title", nullable = false, length = 100)
	private String title;
	
	@Column(name = "author", nullable = false, length = 100)
	private String author;
	
	@Column(name = "editor", length = 100)
	private String editor;
	
	@Column(name = "isbn", length = 50)
	private String isbn;
	
	@Temporal(TemporalType.DATE)
	@Column(name = "publication_date", length = 10)
	private Date publicationDate;
	
	@Column(name = "description", nullable = false, length = 500)
	private String description;
	
	@Column(name = "quantity")
	private Integer quantity;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "library")
	@Cascade({CascadeType.ALL})
	private Set<LibraryPicture> libraryPictures = new HashSet<LibraryPicture>(0);
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "library")
	@Cascade({CascadeType.ALL})
	private Set<LibraryComment> libraryComments = new HashSet<LibraryComment>(0);
	
	public Library() {
	}

	public Library(Member member, String title, String author, String editor,
			String isbn, Date publicationDate, String description,
			Integer quantity, Date createdOn, Date lastUpdate,Set<LibraryPicture> libraryPictures,
			Set<LibraryComment> libraryComments) {
		this.member = member;
		this.title = title;
		this.author = author;
		this.editor = editor;
		this.isbn = isbn;
		this.publicationDate = publicationDate;
		this.description = description;
		this.quantity = quantity;
		this.createdOn = createdOn;
		this.lastUpdate = lastUpdate;
		this.libraryPictures = libraryPictures;
		this.libraryComments = libraryComments;
	}

	
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	
	public Member getMember() {
		return this.member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

	
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	
	public String getAuthor() {
		return this.author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	public String getEditor() {
		return this.editor;
	}

	public void setEditor(String editor) {
		this.editor = editor;
	}

	
	public String getIsbn() {
		return this.isbn;
	}

	public void setIsbn(String isbn) {
		this.isbn = isbn;
	}

	
	public Date getPublicationDate() {
		return this.publicationDate;
	}

	public void setPublicationDate(Date publicationDate) {
		this.publicationDate = publicationDate;
	}

	
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	
	public Integer getQuantity() {
		return this.quantity;
	}

	public void setQuantity(Integer quantity) {
		this.quantity = quantity;
	}

	public Set<LibraryComment> getLibraryComments() {
		return this.libraryComments;
	}

	public void setLibraryComments(Set<LibraryComment> libraryComments) {
		this.libraryComments = libraryComments;
	}
	
	public Set<LibraryPicture> getLibraryPictures() {
		return this.libraryPictures;
	}

	public void setLibraryPictures(Set<LibraryPicture> libraryPictures) {
		this.libraryPictures = libraryPictures;
	}
}
